package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.InvoiceTypeBean;
import com.koron.css2.baseConfig.mapper.InvoiceTypeMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 册本信息-编辑初始化
 * @author 许海宜
 */
public class InvoiceTypeQuery implements ServerInterface {
	private static Logger logger = LogManager.getLogger(InvoiceTypeQuery.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<InvoiceTypeBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", InvoiceTypeBean.class);
		try {
			InvoiceTypeBean bean = JsonUtils.objectToPojo(req.getData(), InvoiceTypeBean.class);
			if(StringUtils.isBlank(bean.getId())){
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "主键不能为空。", void.class);
			}
			InvoiceTypeMapper mapper = factory.getMapper(InvoiceTypeMapper.class);
			bean = mapper.query(bean.getId());
			
			info.setCode(Constant.MESSAGE_INT_SUCCESS);
			info.setDescription("success");
			info.setData(bean);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("操作失败");
			logger.error("操作失败", e);
		}
		return info;
	}

}
